package com.aiguigu.LeCood;

import com.sun.org.apache.xpath.internal.operations.Lt;

public class LongesPalindrom {
    public static void main(String[] args) {
        String s = "babad";
        Object o = new Object();
        
    }



    public static String test(String s){
        int length =s.length();
        if (length< 2){
            return s;
        }

        int maxlength = 1;
        int begin = 0;
        char[] charArray =s.toCharArray();

        for (int i = 0; i < length-1; i++) {
            for (int j = i+1; j <length ; j++) {
                if (j-i+1 >maxlength && validPalindromic(charArray,i,j)){
                      maxlength = j-i+1;
                      begin = i;
                }
            }
        }

        return s.substring(begin,begin+maxlength);
    }

    public static boolean validPalindromic(char[] chars,int left, int right){
        while (left<right){
            if (chars[left]!= chars[right]){
                return  false;
            }
            left++;
            right--;
        }
        return true;
    }
}

